var ListboxAdmin = {
	
	weigths : new Array(),
	send : "",
	
	updateState : function(){
		weight = 0;
		this.send = "";		
		$(".liid").each(function(){
			weight++;
			ListboxAdmin.send += "weight[" + $(this).text() + "]=" + weight + "&";
		});
	},
	
	sendState : function(){
		Cyfy.ajax("ListBoxes", "saveWeights", "", this.send);
		$("#ListBoxesSaveWeight").slideUp();
	},
	
    editItem: function(lid, liid){
        Cyfy.redirectTo('administration/ListBoxes/listOf/' + lid + '/' + liid);
	},
    
	deleteItem: function(liid){
		Cyfy.ajax("ListBoxes", "deleteItem", "", "liid=" + liid, "cyfy.reloadPage();");
	}
}




$(document).ready(function(){

	// hide button
	$("#ListBoxesSaveWeight").hide();
  
	// sortable
	$("#listOfListBoxesItems table tbody").sortable({
		axis: 'y',
		update: function(event, ui) {
			ListboxAdmin.updateState();	
			$("#ListBoxesSaveWeight").slideDown();			
		}
	});
	
	
	$("#listOfListBoxesItems").disableSelection();

	// save button	
	$("#ListBoxesSaveWeight input").click(function(){
		ListboxAdmin.sendState();
		return false;
	});
	
});